var e = require("../../model/awconfig.js"), a = require("../../utils/util.js"), o = getApp();

Page({
    data: {
        modeAD: a.modeAD(),
        showHover: !0,
        hadShowAddTips: 0,
        adHomeImage: "../../images/ad_normal.jpg",
        adHomeTitle: "",
        adHomeAppID: "",
        adHomePath: "",
        openCustomer: 0,
        customerTitle: "客服",
        header_title: "西瓜工具",
        header_message: "不收费，免费提供给大家的小工具。\n如果大家觉得好用，请大家多多分享给好友，告诉好友，是对作者最大的支持，也是作者不断优化改进的动力。",
        header_message_sub: "建议关注“西瓜工具”公众号，获取小程序最新动态和无限制使用教程",
        limitOffsetTime: 12,
        duJiaLimitOffsetTime: 0,
        localShowBannerAD: 1,
        tt: 500,
        kItemsHome: o.globalData.adKeyHome + ";" + o.globalData.adKeyDYDownload,
        aMod: 5,
        showHomeVideoBanner: 1,
        homeVideoADLimit: 1e3,
        onShowCount: 0,
        adBannerType: 1,
        adBannerTypeHome: 1,
        adKeyHome: o.globalData.adKeyHome,
        adKeyDYDownload: o.globalData.adKeyDYDownload,
        adKeyDYVideoInfo: o.globalData.adKeyDYVideoInfo,
        adKeyDYMusic: o.globalData.adKeyDYMusic,
        adKeyUserInifo: o.globalData.adKeyUserInifo,
        adKeyKSDownload: o.globalData.adKeyKSDownload,
        adKeyAlert: o.globalData.adKeyAlert,
        adKeyMore: o.globalData.adKeyMore,
        adKeyWater: o.globalData.adKeyWater,
        adRewardedVideo1: o.globalData.adRewardedVideo1,
        adInterstitial1: o.globalData.adInterstitial1,
        adVideoBanner1: o.globalData.adVideoBanner1,
        ad_mode_banner_1: o.globalData.ad_mode_banner_1,
        ad_mode_hover1: o.globalData.ad_mode_hover1,
        adInterstitialHome: o.globalData.adInterstitialHome,
        interstitialHomeDT: 5e3,
        showHomeAlertAD: 0,
        openHomeRewardedVideoAd: 0,
        showTimeLine: 0,
        openShare: 1,
        shareTips: "免费工具，觉得好用，支持作者，推荐给好友吧",
        shareGroupText: "推荐小程序到微信群",
        shareTimeLineText: "获取推荐的二维码图",
        showDownloadVideo: 1,
        showKSDownloadVideo: 1,
        showHSDownloadVideo: 1,
        showKSTuPianDownloadVideo: 1,
        showParseMusic: 1,
        showParseVideoInfo: 1,
        showParseUserInfo: 1,
        hoverHome: {},
        list_tools: [ {
            title: "使用教程",
            name: "icon",
            color: "cyan",
            icon: "icon",
            app_id: "wx4ed902e153b35e79",
            url: "/pages/tutorialImages/tutorialImages"
        }, {
            title: "常见问题",
            name: "layout",
            color: "cyan",
            icon: "newsfill",
            url: "/pages/question/question"
        } ],
        list_home: [ {
            title: "视频去水印",
            desc: "视频去水印",
            icon: "../../images/dou.jpg",
            url: "/pages/index/index?type=parseVideo",
            app_id: ""
        }, {
            title: "视频去水印2",
            desc: "视频去水印2",
            icon: "../../images/kuai.jpg",
            url: "/pages/kuaishou/kuaishou?type=parseKSVideo"
        }, {
            title: "视频去水印3",
            desc: "视频去水印3",
            icon: "../../images/huoshan.jpg",
            url: "/pages/kuaishou/kuaishou?type=parseHSVideo",
            app_id: ""
        }, {
            title: "图集下载",
            desc: "图集下载",
            icon: "../../images/kuai.jpg",
            url: "/pages/kuaishou/kuaishou?type=parseKSVideo"
        } ],
        list_home_r: []
    },
    onLoad: function(a) {
        var o = this;
        o.setData({
            navTitle: getApp().globalData.appDisplayName
        });
        var t = a.scene;
        if (null != t) {
            var i = decodeURIComponent(t);
            -1 != i.indexOf("Ssource") && (console.log("scene:" + t), wx.reportAnalytics("promotion_source", {
                source: i
            }));
        }
        e.registerConfigCallback(function() {
            o.awconfigSuccessCallback(1);
        }, function(e) {}), o.awconfigSuccessCallback(0), 1 == o.data.openHomeRewardedVideoAd && o.setupVideoAD();
    },
    awconfigSuccessCallback: function(e) {
        var o = wx.getStorageSync("appConfig"), t = this.data.navTitle;
        null != o.navTitle && (t = o.navTitle);
        var i = this.data.list_home;
        null != o.list_home && (i = o.list_home);
        var d = this.data.list_home_r;
        null != o.list_home_r && (d = o.list_home_r);
        var s = this.data.openCustomer;
        null != o.openCustomer && (s = o.openCustomer);
        var n = this.data.customerTitle;
        null != o.customerTitle && (n = o.customerTitle);
        var r = this.data.tt;
        null != o.tt && (r = o.tt);
        var l = this.data.localShowBannerAD;
        0 == e && null != o.localShowBannerAD && (l = o.localShowBannerAD);
        var m = this.data.kItemsHome;
        null != o.kItemsHome && (m = o.kItemsHome);
        var h = this.data.aMod;
        null != o.aMod && (h = o.aMod);
        var u = this.data.showHomeVideoBanner;
        null != o.showHomeVideoBanner && (u = o.showHomeVideoBanner);
        var c = this.data.homeVideoADLimit;
        null != o.homeVideoADLimit && (c = o.homeVideoADLimit);
        var w = this.data.adVideoBanner1;
        null != o.adVideoBanner1 && (w = o.adVideoBanner1);
        var p = this.data.ad_mode_banner_1;
        null != o.ad_mode_banner_1 && (p = o.ad_mode_banner_1);
        var g = this.data.ad_mode_hover1;
        null != o.ad_mode_hover1 && (g = o.ad_mode_hover1);
        var D = this.data.adInterstitialHome;
        null != o.adInterstitialHome && (D = o.adInterstitialHome);
        var T = this.data.interstitialHomeDT;
        null != o.interstitialHomeDT && (T = o.interstitialHomeDT);
        var f = this.data.adKeyHome;
        null != o.adKeyHome && (f = o.adKeyHome);
        var H = this.data.adHomeImage;
        null != o.adHomeImage && (H = o.adHomeImage);
        var v = this.data.adHomeTitle;
        null != o.adHomeTitle && (v = o.adHomeTitle);
        var V = this.data.adHomeAppID;
        null != o.adHomeAppID && (V = o.adHomeAppID);
        var _ = this.data.adHomePath;
        null != o.adHomePath && (_ = o.adHomePath);
        var S = this.data.openShare;
        null != o.openShare && (S = o.openShare);
        var A = this.data.shareTips;
        null != o.shareTips && (A = o.shareTips);
        var I = this.data.shareGroupText;
        null != o.shareGroupText && (I = o.shareGroupText);
        var x = this.data.shareTimeLineText;
        null != o.shareTimeLineText && (x = o.shareTimeLineText);
        var y = this.data.header_message;
        null != o.header_message && (y = o.header_message);
        var K = this.data.header_message_sub;
        null != o.header_message_sub && (K = o.header_message_sub);
        var b = this.data.header_title;
        null != o.header_title && (b = o.header_title);
        var B = this.data.adBannerType;
        null != o.adBannerType && (B = o.adBannerType);
        var P = this.data.adBannerTypeHome;
        null != o.adBannerTypeHome && (P = o.adBannerTypeHome);
        var k = this.data.showHomeAlertAD;
        null != o.showHomeAlertAD && (k = o.showHomeAlertAD);
        var L = this.data.openHomeRewardedVideoAd;
        null != o.openHomeRewardedVideoAd && (L = o.openHomeRewardedVideoAd);
        var C = this.data.showTimeLine;
        null != o.showTimeLine && (C = o.showTimeLine);
        var R = this.data.showDownloadVideo;
        null != o.showDownloadVideo && (R = o.showDownloadVideo);
        var M = this.data.showKSDownloadVideo;
        null != o.showKSDownloadVideo && (M = o.showKSDownloadVideo);
        var E = this.data.showHSDownloadVideo;
        null != o.showHSDownloadVideo && (E = o.showHSDownloadVideo);
        var U = this.data.showKSTuPianDownloadVideo;
        null != o.showKSTuPianDownloadVideo && (U = o.showKSTuPianDownloadVideo);
        var O = this.data.showParseMusic;
        null != o.showParseMusic && (O = o.showParseMusic);
        var J = this.data.showParseVideoInfo;
        null != o.showParseVideoInfo && (J = o.showParseVideoInfo);
        var j = this.data.showParseUserInfo;
        null != o.showParseUserInfo && (j = o.showParseUserInfo);
        var Y = this.data.hoverHome;
        null != o.hoverHome && (Y = o.hoverHome);
        var F = this.data.limitOffsetTime;
        null != o.limitOffsetTime && (F = o.limitOffsetTime), "" == a.getExpiredFormatTime("ExpiredTime") && a.setFirstExpiredTimeStamp(F, "ExpiredTime");
        var q = this.data.duJiaLimitOffsetTime;
        null != o.duJiaLimitOffsetTime && (q = o.duJiaLimitOffsetTime), "" == a.getExpiredFormatTime("DuJiaExpiredTime") && a.setFirstExpiredTimeStamp(q, "DuJiaExpiredTime"), 
        this.data.onShowCount < c ? (console.log("视频广告"), u = 1) : (console.log("普通广告"), 
        u = 0), this.setData({
            config: o,
            navTitle: t,
            list_home: i,
            list_home_r: d,
            openCustomer: s,
            customerTitle: n,
            tt: r,
            localShowBannerAD: l,
            kItemsHome: m,
            aMod: h,
            showHomeVideoBanner: u,
            homeVideoADLimit: c,
            adVideoBanner1: w,
            ad_mode_banner_1: p,
            ad_mode_hover1: g,
            adInterstitialHome: D,
            interstitialHomeDT: T,
            adKeyHome: f,
            adHomeImage: H,
            adHomeTitle: v,
            adHomeAppID: V,
            adHomePath: _,
            openShare: S,
            shareTips: A,
            shareGroupText: I,
            shareTimeLineText: x,
            header_message: y,
            header_message_sub: K,
            header_title: b,
            adBannerType: B,
            adBannerTypeHome: P,
            showHomeAlertAD: k,
            openHomeRewardedVideoAd: L,
            showTimeLine: C,
            showDownloadVideo: R,
            showKSDownloadVideo: M,
            showHSDownloadVideo: E,
            showKSTuPianDownloadVideo: U,
            showParseMusic: O,
            showParseVideoInfo: J,
            showParseUserInfo: j,
            hoverHome: Y,
            limitOffsetTime: F
        }), wx.setNavigationBarTitle({
            title: this.data.navTitle
        });
    },
    showRewardedVideoAdTips: function(e) {
        var a = this;
        wx.showModal({
            title: "提示",
            confirmText: e.confirmText,
            cancelText: e.cancelText,
            content: e.adDesc,
            success: function(e) {
                e.confirm ? a.showRewardedVideoAd() : e.cancel && console.log("用户点击取消");
            }
        });
    },
    showRewardedVideoAd: function() {
        var e = this.data.rewardedVideoAd;
        e.show().catch(function() {
            e.load().then(function() {
                return e.show();
            }).catch(function(e) {
                console.log("激励视频 广告显示失败");
            });
        });
    },
    setupVideoAD: function() {
        var e = this, t = o.globalData.systemInfo.SDKVersion;
        if (!(a.compareVersion(t, "2.6.0") < 0)) {
            var i = wx.createRewardedVideoAd({
                adUnitId: e.data.adRewardedVideo1
            });
            i.onLoad(function() {
                console.log("广告加载成功"), e.setData({
                    videoADLoaded: !0
                });
            }), i.onError(function(a) {
                console.log("广告加载失败"), console.log(a), e.setData({
                    videoADLoaded: !1
                });
            }), i.onClose(function(e) {
                e && e.isEnded || void 0 === e ? (a.setExpiredTimeStamp("ExpiredTime"), a.setExpiredTimeStamp("DuJiaExpiredTime"), 
                wx.showToast({
                    title: "看广告成功"
                })) : wx.showToast({
                    title: "没有看完广告"
                });
            }), e.setData({
                rewardedVideoAd: i
            });
        }
    },
    onShow: function() {
        var e = this;
        e.setData({
            onShowCount: e.data.onShowCount + 1
        }), 1 == e.data.onShowCount || e.data.onShowCount % e.data.aMod == 0 ? (e.setData({
            tempAD: e.data.localShowBannerAD
        }), 1 == e.data.showHomeVideoBanner && e.setData({
            tt: 0
        }), setTimeout(function() {
            e.setData({
                tempAD: 1,
                modeAD: a.modeAD(),
                adKeyHome: a.rAK(e.data.kItemsHome)
            });
        }, e.data.tt)) : e.setData({
            tempAD: 1
        }), e.data.onShowCount > e.data.homeVideoADLimit ? e.setData({
            showHomeVideoBanner: 0
        }) : e.setData({
            showHomeVideoBanner: 1
        }), setTimeout(function() {
            var a = wx.getStorageSync("HadShowAlertAD");
            if (1 == e.data.showHomeAlertAD && 0 == a) {
                console.log("显示插屏广告");
                var o = wx.createInterstitialAd({
                    adUnitId: e.data.adInterstitialHome
                });
                o.onClose(function() {
                    console.log("关闭插屏广告"), wx.setStorageSync("HadShowAlertAD", 1);
                }), o.show().catch(function(e) {
                    console.log(e.errMsg);
                });
            }
        }, e.data.interstitialHomeDT);
    },
    onShareAppMessage: function() {
        return setTimeout(function() {
            console.log("分享成功"), a.setExpiredTimeStamp("ExpiredTime");
        }, 3e3), {
            title: "免费快首、抖因短视频去水印下载",
            path: "/pages/home/home?isShare=1",
            success: function(e) {
                console.log("分享成功"), a.setExpiredTimeStamp("ExpiredTime");
            },
            fail: function(e) {}
        };
    },
    downloadShareImage: function(e) {
        var a = wx.getStorageSync("appConfig"), o = "https://ws3.sinaimg.cn/large/005BYqpgly1fxgok44r0gj30go0gognl.jpg";
        null != a.shareImageURL && (o = a.shareImageURL), wx.showToast({
            title: "下载图片中..."
        }), wx.downloadFile({
            url: o,
            success: function(e) {
                wx.hideToast(), 200 === e.statusCode && (console.log(e.tempFilePath), wx.saveImageToPhotosAlbum({
                    filePath: e.tempFilePath,
                    success: function(e) {
                        wx.showToast({
                            title: "保存到相册成功"
                        });
                    },
                    fail: function(e) {
                        wx.showToast({
                            title: "保存失败"
                        });
                    }
                }));
            },
            fail: function(e) {
                e.errMsg;
                wx.hideToast();
            }
        });
    },
    clickItem: function(e) {
        console.log("clickItem");
        var o = e.currentTarget.dataset.index, t = this.data.list_home[o];
        if (1 == this.data.openHomeRewardedVideoAd && 1 == t.rewardedUnlock && this.data.videoADLoaded && 0 == a.canMake("DuJiaExpiredTime")) this.showRewardedVideoAdTips(t); else {
            var i = JSON.stringify(t), d = e.currentTarget.dataset.url;
            console.log(t), wx.setStorageSync("currentItem", encodeURI(i)), console.log(d), 
            a.forwardItem(t);
        }
    },
    clickRItem: function(e) {
        var o = e.currentTarget.dataset.item, t = JSON.stringify(o);
        console.log(o), wx.setStorageSync("currentItem", encodeURI(t)), console.log(url), 
        a.forwardItem(o);
    },
    toChild: function(e) {
        e.currentTarget.dataset.index;
        var a = e.currentTarget.dataset.url;
        console.log(a), wx.navigateTo({
            url: a
        });
    },
    clickCloseHover: function(e) {
        this.setData({
            showHover: !1
        });
    },
    clickHoverItem: function(e) {
        console.log("clickhoverItem");
        var o = this.data.hoverHome;
        a.forwardItem(o);
    }
});